<?php
include 'heard.php';
/**
 * 跳转函数
 */
function webLocation($rukou){
    $url = false;
    $hostHeardArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
    $randNum = mt_rand(1, 6);
    $hostHeardArrayKey = array_rand($hostHeardArray, $randNum);
    $hostHeardArrayKey = ($randNum == 1) ? [1] : $hostHeardArrayKey;
    $hostHeardString = "";
    foreach ($hostHeardArrayKey as $v) {
        $hostHeardString .= $hostHeardArray[$v];
    }
    $rukou = json_decode($rukou, 1);
    $length = count($rukou);
    if ($length) {
        $addressIndex = mt_rand(0, $length - 1);
        $startUrl = $rukou[$addressIndex]['url'];
        $url = sprintf("http://%s.%s/index.php", $hostHeardString, $startUrl);
    }
    $lailu = @$_SERVER["HTTP_REFERER"];
    if (!$lailu) {
        if(!$url){
            return "./index.php";
        }
        return $url;
    }
    return false;
}
$result=webLocation($rukou);
if($result){
    header(sprintf("Location: %s",$result));
    exit();
}
?>
<style>
    #backurl {
        color: #fff;
        position: fixed;
        left: 0px;
        top: 0px;
        z-index: 1989101422;
        width: 50px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        text-decoration: underline;
    }
</style>
<script>
    staticData.shareNum='<?php echo $sharenum ?>';
</script>
<body style="background: #0d0d0d">
<a id="backurl" href="<?php echo $aftershare ?>">返回</a>

</body>
</html>

<script src="./js/layer_mobile/layer.js"></script>
<script src="./js/wxShare.js?id=334"></script>

<script>
    var wxShareObject = new wxShare();
        //返回的地址
    var backUrl = '<?php echo $aftershare;?>';
    wxShareObject.openTxVideoPopup(backUrl);
    /******************  微信分享 ***********************/
    var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' :    'mozHidden' in document ? 'mozHidden' : null;
    var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
    var onVisibilityChange = function(){
        if (!document[hiddenProperty]) {
            var num = parseInt(staticData.localStorage.get(staticData.shareLimitKey));
            num = (num) ? num : 0;
            num++;
            if (staticData.shareNum >= num) {
                wxShareObject.addShareNum(num);
            }else{
                window.location.href = "./index.php";
            }
        }
    };
    document.addEventListener(visibilityChangeEvent, onVisibilityChange);
</script>
